import msg from "../../utils/msg";
import { uploadPic } from "../../utils/request/api";
import { filePath1 } from "../../utils/request/route";
import User from "../../utils/user"

// pages/user/user.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user: {},
    urls: {
      '1': '',
    },
    getPhone: false,
    showService: false,//点击“联系客服”的弹出层:true
    filePath1,
  },
  //如果登录了就是修改昵称
  checkLogin(){
    let user = new User();
    if(!user.checkLogin(1)) return;
    //修改个人信息
    wx.navigateTo({
      url:"/pages/user/info/info",
    });
  },

  getPhoneNumber(e: any) {
    let code = e.detail.code;
    if (!code) {
      msg.show('请您授权手机号', '否则无法绑定(╥﹏╥)'); return;
    }
    let user = new User;
    user.Login(code);
  },
  onClose() {
    this.setData({ getPhone: false });
    this.setData({ showService: false });//关闭点击“联系客服”的弹出层
  },
  getPhone() {
    this.setData({ getPhone: true });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function () {
    let user = new User;
    if (user.checkLogin()) await user.Login("",false);
    wx.setNavigationBarTitle({
      title: '个人中心',
    })
  },
  async navigate(e: any) {
    let user = new User;
    if (!user.checkLogin(1)) return;
    let id: string = e.currentTarget.dataset.id;
    let url = "";
    switch (id) {
      case "1": url = "./myCom/myCom"; break;
      case "2": url = "./myActiv/myActiv"; break;
      case "3": url = "./myFishLocat/myFishLocat"; break;
      case "4": url="./myFollow/myFollow"; break;
      case "5": url = "./myJoin/myJoin"; break;//报名信息
      case "7": this.getPhone(); return;//绑定手机
      case "8": this.setData({ showService: true }); return;//打开客服
      case "9": 
      if(user.club_id) 
      await msg.confirm('已登录单位:'+user.club_name+'','登录其他单位会覆盖当前单位,是否继续?');
      url = "./merchant/merchant"; break;
      case "10":
        await msg.confirm('是否确认退出登录', '');
        user.logOut(); this.onShow();
        break;
    }
    //
    wx.navigateTo({
      url: url,
    })
  },
  bindPhone() {

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow:async function() {
    let user = new User;
    this.setData({
      user: user,
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})